﻿//---------------------------------------------------------------------
// Author: Harley Green
//
// Description: Class to create a new MSMQueue
//
// Creation Date: 2008/3/8
//---------------------------------------------------------------------

using System.Management.Automation;
using System.Messaging;

namespace Pscx.Commands.Messaging
{
    [Cmdlet(VerbsCommon.New, PscxNouns.MSMQueue, DefaultParameterSetName = "Named", SupportsShouldProcess = true)]
    public class NewMSMQueue : MessageQueueCmdlet
    {
        [Parameter]
        public SwitchParameter Force { get; set; }

        [Parameter]
        public SwitchParameter Transactional { get; set; }

        protected override void ProcessRecord()
        {
            if (!Exists || Force.IsPresent)
            {
                CreateQueue();
            }
        }

        private void CreateQueue()
        {
            if (!ShouldProcess(GetPath())) return;
            using (var queue = MessageQueue.Create(GetPath(), Transactional.ToBool()))
            {
                WriteObject(new MessageQueueInfo(queue));
            }
        }
    }
}